package question3;

import java.util.ArrayList;
import java.util.List;

public class Instructor {
    private String name;
    private Department department; // 所属系
    private List<Subject> taughtSubjects = new ArrayList<>();

    public Instructor(String name) {
        this.name = name;
    }

    // 设置所属系
    public void setDepartment(Department department) {
        this.department = department;
        department.addInstructor(this); // 反向关联系
    }

    // 添加教授的课程
    public void addTaughtSubject(Subject subject) {
        if (taughtSubjects.size() < 3) { // 限制1-3门
            taughtSubjects.add(subject);
            subject.addInstructor(this); // 反向关联课程
        } else {
            System.out.println("指导教师最多教授3门课程");
        }
    }

}
